﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:uc="clr-namespace:FileExplorer.WPF.UserControls"
    xmlns:bc="clr-namespace:FileExplorer.WPF.BaseControls"
    xmlns:cali ="http://www.caliburnproject.org"
    >
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/FileExplorer3.WPF;component/Themes/Default/Colors.xaml" />
        <ResourceDictionary Source="pack://application:,,,/FileExplorer3.WPF;component/Themes/Default/Brushes.xaml" />
        <ResourceDictionary Source="pack://application:,,,/FileExplorer3.WPF;component/Themes/Default/Geometry.xaml" />
        <ResourceDictionary Source="pack://application:,,,/FileExplorer3.WPF;component/Themes/Common/Buttons.xaml" />
        <ResourceDictionary Source="pack://application:,,,/FileExplorer3.WPF;component/Themes/Common/DropDown.xaml" />
        <ResourceDictionary Source="pack://application:,,,/FileExplorer3.WPF;component/Themes/Common/ListViewItem.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <!--Stock from http://msdn.microsoft.com/en-us/library/ms788747.aspx-->
    <Style x:Key="GridViewColumnHeaderGripper" TargetType="Thumb">
        <Setter Property="Width" Value="18" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border Padding="{TemplateBinding Padding}" Background="Transparent">
                        <Rectangle HorizontalAlignment="Center" Width="1" Fill="{TemplateBinding Background}" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="BorderBrush">
            <Setter.Value>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black" Offset="0" />
                    <GradientStop Color="White" Offset="1" />
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ListViewExHeaderMenuItemHeaderStyle" TargetType="{x:Type MenuItem}" >
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="VerticalContentAlignment" Value="Stretch" />
        <Setter Property="HeaderTemplate"  >
            <Setter.Value>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Header}" />
                        <StackPanel x:Name="PART_MatchCount" Orientation="Horizontal" >
                            <TextBlock Text=" ("  />
                            <TextBlock Text="{Binding MatchedCount}" />
                            <TextBlock Text=")" />
                        </StackPanel>
                    </StackPanel>
                    <DataTemplate.Triggers>
                        <DataTrigger Binding="{Binding MatchedCount}" Value="0">
                            <Setter TargetName="PART_MatchCount" Property="Visibility" Value="Collapsed" />
                        </DataTrigger>
                    </DataTemplate.Triggers>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ListViewExColumnHeaderContainerStyle" TargetType="GridViewColumnHeader">
        <Setter Property="BorderBrush" Value="Transparent" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <!--<Setter Property="Visibility" 
                Value="{Binding ColumnsVisibility, RelativeSource={RelativeSource AncestorType={x:Type uc:ListViewEx}}}" />-->
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
                    <Grid>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" >
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames 
                                            Storyboard.TargetName="PART_DropDownGrid"
                                            Storyboard.TargetProperty="Visibility" Duration="0:0:0.1">
                                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Hidden}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <!--<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).
                                                (GradientBrush.GradientStops)[0].(GradientStop.Color)"
                                                Storyboard.TargetName="HeaderBorder">
                                            <EasingColorKeyFrame KeyTime="0" Value="{DynamicResource {x:Static SystemColors.ActiveCaptionColorKey}}" />
                                        </ColorAnimationUsingKeyFrames>-->
                                        <ObjectAnimationUsingKeyFrames 
                                            Storyboard.TargetName="PART_DropDownGrid"
                                            Storyboard.TargetProperty="Visibility" Duration="0:0:0.1">
                                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Visible}" />
                                        </ObjectAnimationUsingKeyFrames>

                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Pressed" />
                                <VisualState x:Name="Disabled" />
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>

                        <!-- Header -->
                        <bc:HotTrack 
                            BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
                            <Grid Margin="2,0">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="6" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="16" />
                                </Grid.ColumnDefinitions>
                                <Path x:Name="PART_SortSymbol" Grid.Row="0" Grid.RowSpan="2" Margin="0, -3,0,0"
                                      Fill="{TemplateBinding Foreground}" HorizontalAlignment="Center" VerticalAlignment="Top" />
                                <ContentPresenter x:Name="HeaderContent" Grid.RowSpan="2" Grid.Row="0" Margin="10,4,4,4"
                                                  RecognizesAccessKey="True" 
                                                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>

                                <Grid x:Name="PART_DropDownGrid" Grid.Column="1" Grid.RowSpan="2" Visibility="Hidden" >
                                    <bc:DropDown x:Name="PART_DropDown"  >
                                        <bc:DropDown.Header>
                                            <Path x:Name="path" Fill="{TemplateBinding Foreground}" 
                                            Data="{StaticResource ExpandedArrow}"
                                            HorizontalAlignment="Center" VerticalAlignment="Center" 
                                            Margin="{TemplateBinding Padding}" IsHitTestVisible="True" />
                                        </bc:DropDown.Header>
                                    </bc:DropDown>
                                </Grid>
                            </Grid>
                        </bc:HotTrack>

                        <Thumb x:Name="PART_HeaderGripper" HorizontalAlignment="Right" Margin="0,0,-9,0" 
                               Style="{StaticResource GridViewColumnHeaderGripper}" />
                    </Grid>
                    <ControlTemplate.Triggers>


                        <Trigger Property="uc:ListViewEx.ColumnHeaderSortDirection" Value="1">
                            <Setter TargetName="PART_SortSymbol" Property="Data" Value="{StaticResource ascArrow}" />
                        </Trigger>
                        <Trigger Property="uc:ListViewEx.ColumnHeaderSortDirection" Value="-1">
                            <Setter TargetName="PART_SortSymbol" Property="Data" Value="{StaticResource descArrow}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ListViewExGridColumnHeaderContainerStyle" 
           BasedOn="{StaticResource ListViewExColumnHeaderContainerStyle}"
           TargetType="GridViewColumnHeader">
        <Setter Property="Width" Value="{Binding ColumnWidth, RelativeSource={RelativeSource TemplatedParent}}" />
    </Style>

    <Style x:Key="ListViewExGridViewScrollViewerStyle" TargetType="{x:Type ScrollViewer}" BasedOn="{StaticResource {x:Static GridView.GridViewScrollViewerStyleKey}}">
        <Setter Property="Focusable" Value="false"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ScrollViewer}">
                    <Grid Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <DockPanel Margin="{TemplateBinding Padding}">
                            <ScrollViewer DockPanel.Dock="Top" Focusable="false" 
                                          HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden">
                                <GridViewHeaderRowPresenter 
                                    AllowsColumnReorder="{Binding TemplatedParent.View.AllowsColumnReorder, RelativeSource={RelativeSource TemplatedParent}}" 
                                    ColumnHeaderContainerStyle="{Binding TemplatedParent.View.ColumnHeaderContainerStyle, RelativeSource={RelativeSource TemplatedParent}}" 
                                    ColumnHeaderToolTip="{Binding TemplatedParent.View.ColumnHeaderToolTip, RelativeSource={RelativeSource TemplatedParent}}" 
                                    ColumnHeaderStringFormat="{Binding TemplatedParent.View.ColumnHeaderStringFormat, RelativeSource={RelativeSource TemplatedParent}}" 
                                    ColumnHeaderContextMenu="{Binding TemplatedParent.View.ColumnHeaderContextMenu, RelativeSource={RelativeSource TemplatedParent}}" 
                                    ColumnHeaderTemplate="{Binding TemplatedParent.View.ColumnHeaderTemplate, RelativeSource={RelativeSource TemplatedParent}}" 
                                    Columns="{Binding TemplatedParent.View.Columns, RelativeSource={RelativeSource TemplatedParent}}" 
                                    ColumnHeaderTemplateSelector="{Binding TemplatedParent.View.ColumnHeaderTemplateSelector, RelativeSource={RelativeSource TemplatedParent}}" 
                                    Margin="2,0,2,0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                            </ScrollViewer>
                            <ContentPresenter Content="{Binding ContentBelowHeader, RelativeSource={RelativeSource  AncestorType={x:Type uc:ListViewEx}}}" DockPanel.Dock="Top" />
                            <ScrollContentPresenter x:Name="PART_ScrollContentPresenter" CanContentScroll="{TemplateBinding CanContentScroll}" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" KeyboardNavigation.DirectionalNavigation="Local" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                        </DockPanel>
                        <ScrollBar x:Name="PART_HorizontalScrollBar" Cursor="Arrow" Maximum="{TemplateBinding ScrollableWidth}" Minimum="0.0" Orientation="Horizontal" Grid.Row="1" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ViewportWidth}"/>
                        <ScrollBar x:Name="PART_VerticalScrollBar" Cursor="Arrow" Grid.Column="1" Maximum="{TemplateBinding ScrollableHeight}" Minimum="0.0" Orientation="Vertical" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ViewportHeight}"/>
                        <DockPanel Background="{Binding Background, ElementName=PART_VerticalScrollBar}" Grid.Column="1" LastChildFill="false" Grid.Row="1">
                            <Rectangle DockPanel.Dock="Left" Fill="White" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" Width="1"/>
                            <Rectangle DockPanel.Dock="Top" Fill="White" Height="1" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
                        </DockPanel>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


    <ControlTemplate x:Key="ListViewExTemplateWithDockableScrollViewer" TargetType="{x:Type uc:ListViewEx}">
        <Border Name="Border" BorderThickness="{TemplateBinding BorderThickness}" 
                            BorderBrush="{TemplateBinding BorderBrush}"
                            Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
            <DockPanel>
                <AdornerDecorator>
                    <bc:DockableScrollViewer
                                    OuterRightContent="{Binding OuterRightContent, RelativeSource={RelativeSource TemplatedParent}}"
                                    RightContent="{Binding RightContent, RelativeSource={RelativeSource TemplatedParent}}">
                        <bc:DockableScrollViewer.OuterTopContent>

                            <DockPanel Margin="{TemplateBinding Padding}" 
                                                   bc:DockableScrollViewer.IsResizable=
                                                   "{Binding OuterTopContent.(bc:DockableScrollViewer.IsResizable), RelativeSource={RelativeSource  TemplatedParent}}"  >
                                <ScrollViewer DockPanel.Dock="Top" Focusable="false" 
                                              Visibility="{Binding ColumnsVisibility, RelativeSource={RelativeSource TemplatedParent}}"
                                                    HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden">
                                    <GridViewHeaderRowPresenter 
                                    AllowsColumnReorder="{Binding View.AllowsColumnReorder, RelativeSource={RelativeSource TemplatedParent}}" 
                                    ColumnHeaderContainerStyle="{Binding View.ColumnHeaderContainerStyle, RelativeSource={RelativeSource TemplatedParent}}" 
                                    ColumnHeaderToolTip="{Binding View.ColumnHeaderToolTip, RelativeSource={RelativeSource TemplatedParent}}" 
                                    ColumnHeaderStringFormat="{Binding View.ColumnHeaderStringFormat, RelativeSource={RelativeSource TemplatedParent}}" 
                                    ColumnHeaderContextMenu="{Binding View.ColumnHeaderContextMenu, RelativeSource={RelativeSource TemplatedParent}}" 
                                    ColumnHeaderTemplate="{Binding View.ColumnHeaderTemplate, RelativeSource={RelativeSource TemplatedParent}}" 
                                    Columns="{Binding View.Columns, RelativeSource={RelativeSource TemplatedParent}}" 
                                    ColumnHeaderTemplateSelector="{Binding View.ColumnHeaderTemplateSelector, RelativeSource={RelativeSource TemplatedParent}}" 
                                    Margin="2,0,2,0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                                </ScrollViewer>
                                <ContentPresenter Content="{Binding OuterTopContent, RelativeSource={RelativeSource  TemplatedParent}}"  />
                            </DockPanel>

                        </bc:DockableScrollViewer.OuterTopContent>
                        <ItemsPresenter x:Name="lvItemsPresenter" />

                    </bc:DockableScrollViewer>
                    <!--<ScrollViewer Style="{StaticResource ListViewExGridViewScrollViewerStyle}">
                                    <ItemsPresenter />
                                </ScrollViewer>-->
                </AdornerDecorator>
            </DockPanel>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsGrouping" Value="true">
                <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
            </Trigger>

            <Trigger Property="IsEnabled" Value="false">
                <Setter TargetName="Border" Property="Opacity" 
                        Value="0.5"/>
                <!--<Setter TargetName="Border" Property="Background" 
                        Value="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"/>-->
            </Trigger>

        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style TargetType="{x:Type uc:ListViewEx}">
        <Setter Property="VirtualizingPanel.IsVirtualizing" Value="False" />
        <Setter Property="TextSearch.TextPath" Value="EntryModel.Label" />
        <Setter Property="IsTextSearchEnabled" Value="True" />
        <!--<Setter Property="TextRootItem.TextPath" Value="EmbeddedModel.Label" />-->
        <Setter Property="Template" Value="{StaticResource ListViewExTemplateWithDockableScrollViewer}" />
        <!--<Setter Property="SelectionMode" Value="Extended" />-->
        <Style.Triggers>
            <!-- Cannot set in GridView style, so set here. -->
            <Trigger Property="ViewMode" Value="Grid">
                <Setter Property="ItemContainerStyle" Value="{StaticResource FileListItemStyle_Grid}" />
            </Trigger>
        </Style.Triggers>
    </Style>





</ResourceDictionary>